<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
	function index(){
		$this->display();
	}

		function check(){
			if($_POST['verify'] == ""){	
				$data['status']=0;
				$data['info']='请输入验证码!';
				$this->ajaxReturn($data);
				exit();
			}
			if($_POST['username'] == ""){
				$data['status']=1;
				$data['info']='用户名不能为空!';
				$this->ajaxReturn($data);
				exit();
			}
			if($_POST['password'] == ''){
				$data['status']=2;
				$data['info']='密码不能为空!';
				$this->ajaxReturn($data);
				exit();
			}
			$verifyOb=new \Think\Verify;
			$verRe=$verifyOb->check($_POST['verify']);
			if(!$verRe){
				$data['status']=3;
				$data['info']='验证码错误!';
				$this->ajaxReturn($data);
				exit();
			}else{
				$adminOb=M('Admin');
				$password=$_POST['password'];
				$adminRe=$adminOb->where("username='{$_POST['username']}' and password='{$password}'")->find();
				if(!$adminRe){
					$data['status']=4;
					$data['info']='账号或密码错误!';
					$this->ajaxReturn($data);
					exit();
				}else{
					$_SESSION['adminid'] = $adminRe['id'];
					$_SESSION['adminusername'] = $adminRe['username'];
					$data['status']=5;
					
					$data['url']=U("Admin/Index/index");
					$this->ajaxReturn($data);
				}

			}			
 	}
 		
}





